package com.black.web.app.exercise.personalize;

import com.black.app.domain.req.exercise.add.AppExercisePersonalizeAddReq;
import com.black.app.domain.req.exercise.edit.AppExercisePersonalizeEditReq;
import com.black.app.domain.req.exercise.query.AppExercisePersonalizeQueryReq;
import com.black.app.domain.resp.exercise.AppExercisePersonalizeResp;
import com.black.app.service.exercise.AppExercisePersonalizeService;
import com.black.common.core.controller.BaseController;
import com.black.common.core.domain.R;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

@Api(tags = "app-锻炼私人定制Personalize的Api")
@RestController
@RequestMapping(value = "/app/exercise/personalize")
public class AppExercisePersonalizeController extends BaseController {
    @Autowired
    private AppExercisePersonalizeService appExercisePersonalizeService;

    /*
     * 分页查询
     * */
    @PreAuthorize("@ss.hasAppPermi()")
    @ApiOperation(value = "分页查询")
    @GetMapping("/list")
    public R<PageInfo<AppExercisePersonalizeResp>> pagination(AppExercisePersonalizeQueryReq req){
        PageInfo<AppExercisePersonalizeResp> page = this.appExercisePersonalizeService.paginationQuery(req);
        return R.ok(page);
    }
    /*
    * 根据id查询
    * */
    @PreAuthorize("@ss.hasAppPermi()")
    @ApiOperation(value = "根据id查询")
    @GetMapping("/{id}")
    public R<AppExercisePersonalizeResp> findById(@PathVariable(value = "id") Long id){
        AppExercisePersonalizeResp resp=this.appExercisePersonalizeService.findById(id);
        return R.ok(resp);
    }

    /*
     * 新增私人定制
     * */
    @PreAuthorize("@ss.hasAppPermi()")
    @ApiOperation(value = "私人定制新增")
    @PostMapping
    public R add(@RequestBody @Valid AppExercisePersonalizeAddReq req){
        boolean res = this.appExercisePersonalizeService.add(req);
        return super.isSuccess(res);
    }

    /*
    * 删除私人定制
    * */
    //log是给后台用的
    @PreAuthorize("@ss.hasAppPermi()")
    @ApiOperation(value = "删除")
    @DeleteMapping(value = "/{ids}")
    public R delete(@PathVariable(value = "ids") Long[] ids){
        boolean res = this.appExercisePersonalizeService.deleteById(ids);
        return super.isSuccess(res);
    }

    /*
    * 编辑修改私人定制
    * */
    @PreAuthorize("@ss.hasAppPermi()")
    @ApiOperation(value = "编辑修改")
    @PutMapping
    public R edit(@RequestBody @Valid AppExercisePersonalizeEditReq req){
        boolean res = this.appExercisePersonalizeService.edit(req);
        return super.isSuccess(res);
    }

}
